package com.iterator.iterator;

import java.util.Iterator;

/**
 * 用于遍历计算机学院中，系 的迭代器
 */
public class ComputerCollegeIterator implements Iterator {

    //需要知道department是以什么方式存放的 =》 数组
    Department[] departments ;
    int position = 0 ; //当前遍历的位置

    //构造
    public ComputerCollegeIterator(Department[] departments) {
        this.departments = departments;
    }

    //是否还存在下一个元素
    @Override
    public boolean hasNext() {
        if (position >= departments.length || departments[position] == null){
            return false;
        }
        return true;
    }

    //拿到下一个元素
    @Override
    public Object next() {
        Department department = departments[position];
        position += 1 ;
        return department;
    }

    //删除方法  暂时不需要，所以空实现
    @Override
    public void remove() {
        Iterator.super.remove();
    }
}
